#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

import os
import shutil

############################################################################

src_file_path = r'/rootfs/media/kasim/Data1/data/VideoGenderCropPerson'
dst_file_path = r'/rootfs/media/kasim/Data1/data/ErisedPersonGender'
# move_list_file = r'/rootfs/media/kasim/Data1/data/VideoGenderCropPerson/val_person_image_gender.txt'
move_list_file = r'/rootfs/media/kasim/Data1/data/VideoGenderCropPerson/train_person_image_gender.txt'

try:
    file_count = 0

    if not os.path.exists(dst_file_path):
        os.makedirs(dst_file_path)
        os.system('chmod a+wr {}'.format(dst_file_path))

    with open(os.path.join(src_file_path, move_list_file), 'r', encoding='utf-8') as file:
        for line in file.readlines():
            file_name = line.split()[0]
            src_path = os.path.join(src_file_path, file_name)
            dst_path = os.path.join(dst_file_path, file_name)
            dir_name = os.path.dirname(dst_path)
            if not os.path.exists(dir_name):
                os.makedirs(dir_name)
            shutil.move(src_path, dst_path)
            file_count += 1

            if file_count % 100 == 0:
                print('Process Move File Count:', file_count)
    os.system('chmod a+wr {} -Rf'.format(dst_file_path))
    print('Process Copy File Count:', file_count)

except Exception as e:
    print(e)

print('Finish!')

